$NG.AllReady(function (page, { useValuesChange,useDataIndexChange,useUpdateRows,useUpdateRow }) {
    const mstform = $NG.getCmpApi("p_form_analysis_income")
    if(page.oType == 'add' || page.oType == 'edit'){
        getPtInfoByPhid()
        getCntCount("p_form_analysis_income","u_cnt_name",()=>{
            getCntMInfoByPhid()
        })
    }
        cntMFilter()
    useValuesChange(({args})=>{
        getPtInfoByPhid()
        cntMFilter()
        getCntCount("p_form_analysis_income","u_cnt_name",()=>{
            getCntMInfoByPhid()
        })
    },"p_form_analysis_income.phid_pc")

    useValuesChange(({args})=>{
        getCntMInfoByPhid()
    },"p_form_analysis_income.u_cnt_name")
    /**
     * 
     * 功能扩展区
     * 
    */
    //获取项目信息
    function getPtInfoByPhid() {
        if (mstform.getItem("phid_pc").getValue()) {
          $NG.execServer("getPtInfoByPhid", { phid: mstform.getItem("phid_pc").getValue() }, function (res) {
            if(res.count == 0) return
            const datas = JSON.parse(res.data)[0].extendObjects;
            console.log(datas);
            $NG.updateState((updater) => {
              updater.data.p_form_analysis_income.setProps({
                u_pc_no:datas.pc_no,
                //事业部
                phid_org: { value: datas.division_phid, label: datas.division_name },
                //区域中心
                u_regional_center: { value: datas.regional_center_phid, label: datas.regional_center_name },
                //产品线
                u_product_line: { value: datas.midwife_phid, label: datas.midwife_name },
              });
            });
          });
        }
    }
    //     //获取合同信息
    function getCntMInfoByPhid() {
        $NG.execServer("getCntMInfoByPhid", { phid: mstform.getItem("u_cnt_name").getValue() }, function (res) {
        if(res.count == 0) return 
          const datas = JSON.parse(res.data)[0].extendObjects;
          console.log(datas);
          $NG.updateState((updater) => {
            updater.data.p_form_analysis_income.setProps({
                u_cnt_no: datas.pcm_no, //合同名称
                u_cnt_namt:datas.cnt_sum_vat_fc,
                u_sl:datas.user_taxrate
            });
          });
        });
    }

    /**
     * 过滤区
     * */ 
    //合同根据项目ID过滤
    cntMFilter()
function cntMFilter() {
  $NG.updateUI((updater, state) => {
      console.log('过滤参数检查', updater);
      updater.form.p_form_analysis_income.u_cnt_name.setProps({
          onBeforeOpen: async () => {
              var phid_pc = $NG.getCmpApi('p_form_analysis_income').getItem('phid_pc').getValue();
              if (!phid_pc) {
                  $NG.alert("请先选择项目");
                  return false;
              } else {
                  return true;
              }
          },
          ...(!!$NG.getCmpApi('p_form_analysis_income').getItem('phid_pc').getValue() && {
              clientSqlFilter: {
                  bill_type: 1,//合同类型
                  phid_pc: $NG.getCmpApi('p_form_analysis_income').getItem('phid_pc').getValue()
              }
          }),
      });
  });
}
    //获取合同数量
    function getCntCount(table,key,fun){
        if(!$NG.getCmpApi(table).getItem("phid_pc").getValue()) return 
        $NG.execServer("getCntCount",{type:1,phid_pc:$NG.getCmpApi(table).getItem("phid_pc").getValue()},(res)=>{
          console.log(res,'count');
          switch(res.count){
            case 0:
              return
            case 1:
              const datas = JSON.parse(res.data)[0].extendObjects
              const temp_map = {}
              temp_map[key] = datas.phid
              temp_map[`${key}_EXName`] = datas.bill_name
              $NG.updateState((updater)=>{
                updater.data[table].setProps({
                  ...temp_map
                })
                setTimeout(()=>{
                  if(fun){
                    fun()
                  }
                },200)
              })
          }
        })
      }
})  